import { util } from '@kit.ArkTS'

const bufferToStr = (value: ArrayBuffer) => {
  return util.TextDecoder.create('utf-8').decodeToString(new Uint8Array(value))
}

const valueToStr = (value: String | ArrayBuffer) => {
  if (value instanceof ArrayBuffer) {
    return bufferToStr(value)
  }
  return valueToStr
}

export const bufferUtils = { bufferToStr, valueToStr }